package com.shixulin.controller;


import com.shixulin.domain.ResponseResult;
import com.shixulin.entity.DTO.QuestionQueryDTO;
import com.shixulin.entity.PaperQuestion;
import com.shixulin.entity.QuestionBank;
import com.shixulin.service.PaperQuestionService;
import com.shixulin.service.QuestionBankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/teacher")
public class QuestionController {

    @Autowired
    private QuestionBankService questionBankService;

    @Autowired
    private PaperQuestionService paperQuestionService;

    @PostMapping("/uploadQuestion")
    public ResponseResult uploadQuestion(@RequestBody QuestionBank questionBank){
        QuestionBank question = new QuestionBank(null,questionBank.getSubjectId(),questionBank.getTeacherId(),questionBank.getQuestionType(),questionBank.getQuestion(),
                questionBank.getOptionA(), questionBank.getOptionB(), questionBank.getOptionC(), questionBank.getOptionD(), questionBank.getScore(),
                questionBank.getCorrectAnswer(), questionBank.getCorrectAnswerJudge());

        return questionBankService.uploadQuestion(question);
    }

    @PostMapping("/getQuestionBank")
    public ResponseResult getQuestionBank(@RequestBody QuestionQueryDTO questionQueryDTO){
        return questionBankService.getQuestionBankByPage(questionQueryDTO);
    }

    @GetMapping("/getQuestions/{id}")
    public ResponseResult getQuestions(@PathVariable("id") int id){
        return questionBankService.getQuestionsById(id);
    }

    @PostMapping("/editQuestion")
    public ResponseResult editQuestion(@RequestBody QuestionBank questionBank){
        QuestionBank question = new QuestionBank(questionBank.getId(),questionBank.getSubjectId(),questionBank.getTeacherId(),questionBank.getQuestionType(),questionBank.getQuestion(),
                questionBank.getOptionA(), questionBank.getOptionB(), questionBank.getOptionC(), questionBank.getOptionD(), questionBank.getScore(),
                questionBank.getCorrectAnswer(), questionBank.getCorrectAnswerJudge());
        return questionBankService.editQuestion(question);
    }

    @GetMapping("/deleteQuestionById/{id}")
    public ResponseResult deleteQuestionById(@PathVariable("id")int id){

        return questionBankService.deleteQuestionById(id) ;
    }
    //对试卷试卷添加题目，获取科目的题目
    @GetMapping("/selectSubjectQuestion/{subjectId}")
    public ResponseResult selectSubjectQuestion(@PathVariable("subjectId") int subjectId){
        return questionBankService.selectSubjectQuestion(subjectId);
    }

}
